﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.DomainObjects;
using DomainDriver.DomainModeling.StorageManagers.EntityFrameworkStorage;
using AutomotivePricingModel.ValueObjects.YearlyFinancialAssessments;

namespace AutomotivePricingModel.Companies
{
    public partial class Company : KeyedDomainObjectBase<Guid, Company>
    {
        private Nullable<Guid> m_CountryOfHeadquarters;
        private string m_CompanyName;
        private string m_CeoName;
        private string m_FounderName;
        private Nullable<DateTime> m_CompanyFoundingDate;
        private Nullable<Guid> m_EarningsHistoryId;
        private YearlyFinancialAssessment m_EarningsHistory;
        private byte[] m_TestBytes;

        public Company()
        {
            m_Key = Guid.NewGuid();
            m_CountryOfHeadquarters = null;
            m_CompanyName = string.Empty;
            m_CeoName = string.Empty;
            m_FounderName = string.Empty;
            m_CompanyFoundingDate = null;
            m_EarningsHistory = new YearlyFinancialAssessment();
            m_EarningsHistoryId = m_EarningsHistory.Key;
            m_TestBytes = new byte[] { (byte)DateTime.Now.Second, (byte)DateTime.Now.Millisecond };
        }

        public Nullable<Guid> CountryOfHeadquarters
        {
            get { return m_CountryOfHeadquarters; }
            set { m_CountryOfHeadquarters = value; }
        }

        [NotMapped]
        public string CompanyName
        {
            get { return m_CompanyName; }
            set { m_CompanyName = value; }
        }

        [ForceMapped]
        internal string EF_CompanyName
        {
            get { return m_CompanyName; }
            set { m_CompanyName = value; }
        }

        public string CeoName
        {
            get { return m_CeoName; }
            set { m_CeoName = value; }
        }

        public string FounderName
        {
            get { return m_FounderName; }
            set { m_FounderName = value; }
        }

        public Nullable<DateTime> CompanyFoundingDate
        {
            get { return m_CompanyFoundingDate; }
            set { m_CompanyFoundingDate = value; }
        }

        public YearlyFinancialAssessment EarningsHistory
        {
            get { return m_EarningsHistory; }
        }

        #region DomainObject Methods

        public override Company Copy()
        {
            Company copy = new Company();
            CopyTo(copy);
            return copy;
        }

        public override void CopyTo(Company otherObject)
        {
            if (otherObject.m_Key != m_Key)
            { otherObject.m_Key = m_Key; }
            if (otherObject.m_CountryOfHeadquarters != m_CountryOfHeadquarters)
            { otherObject.m_CountryOfHeadquarters = m_CountryOfHeadquarters; }
            if (otherObject.m_CompanyName != m_CompanyName)
            { otherObject.m_CompanyName = m_CompanyName; }
            if (otherObject.m_CeoName != m_CeoName)
            { otherObject.m_CeoName = m_CeoName; }
            if (otherObject.m_FounderName != m_FounderName)
            { otherObject.m_FounderName = m_FounderName; }
            if (otherObject.m_CompanyFoundingDate != m_CompanyFoundingDate)
            { otherObject.m_CompanyFoundingDate = m_CompanyFoundingDate; }
            if (otherObject.m_EarningsHistoryId != m_EarningsHistoryId)
            { otherObject.m_EarningsHistoryId = m_EarningsHistoryId; }
            if (m_EarningsHistory == null)
            { otherObject.m_EarningsHistory = null; }
            else if (!m_EarningsHistory.Equals(otherObject.m_EarningsHistory))
            { otherObject.m_EarningsHistory = m_EarningsHistory.Copy(); }
            if (!otherObject.m_TestBytes.SequenceEqual(m_TestBytes))
            { m_TestBytes.CopyTo(otherObject.m_TestBytes, 0); }
        }

        public override bool Equals(Company otherObject)
        {
            if (otherObject.m_Key != m_Key)
            { return false; }
            if (otherObject.m_CountryOfHeadquarters != m_CountryOfHeadquarters)
            { return false; }
            if (otherObject.m_CompanyName != m_CompanyName)
            { return false; }
            if (otherObject.m_CeoName != m_CeoName)
            { return false; }
            if (otherObject.m_FounderName != m_FounderName)
            { return false; }
            if (otherObject.m_CompanyFoundingDate != m_CompanyFoundingDate)
            { return false; }
            if (otherObject.m_EarningsHistoryId != m_EarningsHistoryId)
            { return false; }
            if (m_EarningsHistory == null)
            { return (otherObject.m_EarningsHistory == null); }
            else if (!m_EarningsHistory.Equals(otherObject.m_EarningsHistory))
            { return false; }
            if (!otherObject.m_TestBytes.SequenceEqual(m_TestBytes))
            { return false; }
            return true;
        }

        #endregion
    }
}